home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / src / gdb-4.12 / gdb / eval.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-03  |  35.2 KB  |  1,231 lines

  1. /* Evaluate expressions for GDB.
  2.    Copyright 1986, 1987, 1989, 1991, 1992 Free Software Foundation, Inc.
  3.  
  4. This file is part of GDB.
  5.  
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include "defs.h"
  21. #include "symtab.h"
  22. #include "gdbtypes.h"
  23. #include "value.h"
  24. #include "expression.h"
  25. #include "target.h"
  26. #include "frame.h"
  27. #include "demangle.h"
  28. #include "language.h"    /* For CAST_IS_CONVERSION */
  29.  
  30. /* Values of NOSIDE argument to eval_subexp.  */
  31. enum noside
  32. { EVAL_NORMAL,
  33.   EVAL_SKIP,            /* Only effect is to increment pos.  */
  34.   EVAL_AVOID_SIDE_EFFECTS    /* Don't modify any variables or
  35.                    call any functions.  The value
  36.                    returned will have the correct
  37.                    type, and will have an
  38.                    approximately correct lvalue
  39.                    type (inaccuracy: anything that is
  40.                    listed as being in a register in
  41.                    the function in which it was
  42.                    declared will be lval_register).  */
  43. };
  44.  
  45. /* Prototypes for local functions. */
  46.  
  47. static value
  48. evaluate_subexp_for_sizeof PARAMS ((struct expression *, int *));
  49.  
  50. static value
  51. evaluate_subexp_with_coercion PARAMS ((struct expression *, int *,
  52.                        enum noside));
  53.  
  54. static value
  55. evaluate_subexp_for_address PARAMS ((struct expression *, int *,
  56.                      enum noside));
  57.  
  58. static value
  59. evaluate_subexp PARAMS ((struct type *, struct expression *, int *,
  60.              enum noside));
  61.  
  62.  
  63. /* Parse the string EXP as a C expression, evaluate it,
  64.    and return the result as a number.  */
  65.  
  66. CORE_ADDR
  67. parse_and_eval_address (exp)
  68.      char *exp;
  69. {
  70.   struct expression *expr = parse_expression (exp);
  71.   register CORE_ADDR addr;
  72.   register struct cleanup *old_chain = 
  73.       make_cleanup (free_current_contents, &expr);
  74.  
  75.   addr = value_as_pointer (evaluate_expression (expr));
  76.   do_cleanups (old_chain);
  77.   return addr;
  78. }
  79.  
  80. /* Like parse_and_eval_address but takes a pointer to a char * variable
  81.    and advanced that variable across the characters parsed.  */
  82.  
  83. CORE_ADDR
  84. parse_and_eval_address_1 (expptr)
  85.      char **expptr;
  86. {
  87.   struct expression *expr = parse_exp_1 (expptr, (struct block *)0, 0);
  88.   register CORE_ADDR addr;
  89.   register struct cleanup *old_chain =
  90.       make_cleanup (free_current_contents, &expr);
  91.  
  92.   addr = value_as_pointer (evaluate_expression (expr));
  93.   do_cleanups (old_chain);
  94.   return addr;
  95. }
  96.  
  97. value
  98. parse_and_eval (exp)
  99.      char *exp;
  100. {
  101.   struct expression *expr = parse_expression (exp);
  102.   register value val;
  103.   register struct cleanup *old_chain
  104.     = make_cleanup (free_current_contents, &expr);
  105.  
  106.   val = evaluate_expression (expr);
  107.   do_cleanups (old_chain);
  108.   return val;
  109. }
  110.  
  111. /* Parse up to a comma (or to a closeparen)
  112.    in the string EXPP as an expression, evaluate it, and return the value.
  113.    EXPP is advanced to point to the comma.  */
  114.  
  115. value
  116. parse_to_comma_and_eval (expp)
  117.      char **expp;
  118. {
  119.   struct expression *expr = parse_exp_1 (expp, (struct block *) 0, 1);
  120.   register value val;
  121.   register struct cleanup *old_chain
  122.     = make_cleanup (free_current_contents, &expr);
  123.  
  124.   val = evaluate_expression (expr);
  125.   do_cleanups (old_chain);
  126.   return val;
  127. }
  128.  
  129. /* Evaluate an expression in internal prefix form
  130.    such as is constructed by parse.y.
  131.  
  132.    See expression.h for info on the format of an expression.  */
  133.  
  134. static value evaluate_subexp ();
  135. static value evaluate_subexp_for_address ();
  136. static value evaluate_subexp_for_sizeof ();
  137. static value evaluate_subexp_with_coercion ();
  138.  
  139. value
  140. evaluate_expression (exp)
  141.      struct expression *exp;
  142. {
  143.   int pc = 0;
  144.   return evaluate_subexp (NULL_TYPE, exp, &pc, EVAL_NORMAL);
  145. }
  146.  
  147. /* Evaluate an expression, avoiding all memory references
  148.    and getting a value whose type alone is correct.  */
  149.  
  150. value
  151. evaluate_type (exp)
  152.      struct expression *exp;
  153. {
  154.   int pc = 0;
  155.   return evaluate_subexp (NULL_TYPE, exp, &pc, EVAL_AVOID_SIDE_EFFECTS);
  156. }
  157.  
  158. static value
  159. evaluate_subexp (expect_type, exp, pos, noside)
  160.      struct type *expect_type;
  161.      register struct expression *exp;
  162.      register int *pos;
  163.      enum noside noside;
  164. {
  165.   enum exp_opcode op;
  166.   int tem, tem2, tem3;
  167.   register int pc, pc2 = 0, oldpos;
  168.   register value arg1 = NULL, arg2 = NULL, arg3;
  169.   struct type *type;
  170.   int nargs;
  171.   value *argvec;
  172.  
  173.   pc = (*pos)++;
  174.   op = exp->elts[pc].opcode;
  175.  
  176.   switch (op)
  177.     {
  178.     case OP_SCOPE:
  179.       tem = longest_to_int (exp->elts[pc + 2].longconst);
  180.       (*pos) += 4 + BYTES_TO_EXP_ELEM (tem + 1);
  181.       arg1 = value_struct_elt_for_reference (exp->elts[pc + 1].type,
  182.                          0,
  183.                          exp->elts[pc + 1].type,
  184.                          &exp->elts[pc + 3].string,
  185.                          expect_type);
  186.       if (arg1 == NULL)
  187.     error ("There is no field named %s", &exp->elts[pc + 3].string);
  188.       return arg1;
  189.  
  190.     case OP_LONG:
  191.       (*pos) += 3;
  192.       return value_from_longest (exp->elts[pc + 1].type,
  193.                  exp->elts[pc + 2].longconst);
  194.  
  195.     case OP_DOUBLE:
  196.       (*pos) += 3;
  197.       return value_from_double (exp->elts[pc + 1].type,
  198.                 exp->elts[pc + 2].doubleconst);
  199.  
  200.     case OP_VAR_VALUE:
  201.       (*pos) += 3;
  202.       if (noside == EVAL_SKIP)
  203.     goto nosideret;
  204.       if (noside == EVAL_AVOID_SIDE_EFFECTS)
  205.     {
  206.       struct symbol * sym = exp->elts[pc + 2].symbol;
  207.       enum lval_type lv;
  208.  
  209.       switch (SYMBOL_CLASS (sym))
  210.         {
  211.         case LOC_CONST:
  212.         case LOC_LABEL:
  213.         case LOC_CONST_BYTES:
  214.           lv = not_lval;
  215.           break;
  216.  
  217.         case LOC_REGISTER:
  218.         case LOC_REGPARM:
  219.           lv = lval_register;
  220.           break;
  221.  
  222.         default:
  223.           lv = lval_memory;
  224.           break;
  225.         }
  226.  
  227.       return value_zero (SYMBOL_TYPE (sym), lv);
  228.     }
  229.       else
  230.     return value_of_variable (exp->elts[pc + 2].symbol,
  231.                   exp->elts[pc + 1].block);
  232.  
  233.     case OP_LAST:
  234.       (*pos) += 2;
  235.       return
  236.     access_value_history (longest_to_int (exp->elts[pc + 1].longconst));
  237.  
  238.     case OP_REGISTER:
  239.       (*pos) += 2;
  240.       return value_of_register (longest_to_int (exp->elts[pc + 1].longconst));
  241.  
  242.     case OP_BOOL:
  243.       (*pos) += 2;
  244.       return value_from_longest (builtin_type_chill_bool,
  245.                  exp->elts[pc + 1].longconst);
  246.  
  247.     case OP_INTERNALVAR:
  248.       (*pos) += 2;
  249.       return value_of_internalvar (exp->elts[pc + 1].internalvar);
  250.  
  251.     case OP_STRING:
  252.       tem = longest_to_int (exp->elts[pc + 1].longconst);
  253.       (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
  254.       if (noside == EVAL_SKIP)
  255.     goto nosideret;
  256.       return value_string (&exp->elts[pc + 2].string, tem);
  257.  
  258.     case OP_BITSTRING:
  259.       error ("support for OP_BITSTRING unimplemented");
  260.       break;
  261.  
  262.     case OP_ARRAY:
  263.       (*pos) += 3;
  264.       tem2 = longest_to_int (exp->elts[pc + 1].longconst);
  265.       tem3 = longest_to_int (exp->elts[pc + 2].longconst);
  266.       nargs = tem3 - tem2 + 1;
  267.       argvec = (value *) alloca (sizeof (value) * nargs);
  268.       for (tem = 0; tem < nargs; tem++)
  269.     {
  270.       /* Ensure that array expressions are coerced into pointer objects. */
  271.       argvec[tem] = evaluate_subexp_with_coercion (exp, pos, noside);
  272.     }
  273.       if (noside == EVAL_SKIP)
  274.     goto nosideret;
  275.       return (value_array (tem2, tem3, argvec));
  276.       break;
  277.  
  278.     case TERNOP_COND:
  279.       /* Skip third and second args to evaluate the first one.  */
  280.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  281.       if (value_logical_not (arg1))
  282.     {
  283.       evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
  284.       return evaluate_subexp (NULL_TYPE, exp, pos, noside);
  285.     }
  286.       else
  287.     {
  288.       arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  289.       evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
  290.       return arg2;
  291.     }
  292.  
  293.     case OP_FUNCALL:
  294.       (*pos) += 2;
  295.       op = exp->elts[*pos].opcode;
  296.       if (op == STRUCTOP_MEMBER || op == STRUCTOP_MPTR)
  297.     {
  298.       int fnptr;
  299.  
  300.       nargs = longest_to_int (exp->elts[pc + 1].longconst) + 1;
  301.       /* First, evaluate the structure into arg2 */
  302.       pc2 = (*pos)++;
  303.  
  304.       if (noside == EVAL_SKIP)
  305.         goto nosideret;
  306.  
  307.       if (op == STRUCTOP_MEMBER)
  308.         {
  309.           arg2 = evaluate_subexp_for_address (exp, pos, noside);
  310.         }
  311.       else
  312.         {
  313.           arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  314.         }
  315.  
  316.       /* If the function is a virtual function, then the
  317.          aggregate value (providing the structure) plays
  318.          its part by providing the vtable.  Otherwise,
  319.          it is just along for the ride: call the function
  320.          directly.  */
  321.  
  322.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  323.  
  324.       fnptr = longest_to_int (value_as_long (arg1));
  325.  
  326.       if (METHOD_PTR_IS_VIRTUAL(fnptr))
  327.         {
  328.           int fnoffset = METHOD_PTR_TO_VOFFSET(fnptr);
  329.           struct type *basetype;
  330.           struct type *domain_type =
  331.           TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1)));
  332.           int i, j;
  333.           basetype = TYPE_TARGET_TYPE (VALUE_TYPE (arg2));
  334.           if (domain_type != basetype)
  335.           arg2 = value_cast(lookup_pointer_type (domain_type), arg2);
  336.           basetype = TYPE_VPTR_BASETYPE (domain_type);
  337.           for (i = TYPE_NFN_FIELDS (basetype) - 1; i >= 0; i--)
  338.         {
  339.           struct fn_field *f = TYPE_FN_FIELDLIST1 (basetype, i);
  340.           /* If one is virtual, then all are virtual.  */
  341.           if (TYPE_FN_FIELD_VIRTUAL_P (f, 0))
  342.             for (j = TYPE_FN_FIELDLIST_LENGTH (basetype, i) - 1; j >= 0; --j)
  343.               if (TYPE_FN_FIELD_VOFFSET (f, j) == fnoffset)
  344.             {
  345.               value temp = value_ind (arg2);
  346.               arg1 = value_virtual_fn_field (&temp, f, j, domain_type, 0);
  347.               arg2 = value_addr (temp);
  348.               goto got_it;
  349.             }
  350.         }
  351.           if (i < 0)
  352.         error ("virtual function at index %d not found", fnoffset);
  353.         }
  354.       else
  355.         {
  356.           VALUE_TYPE (arg1) = lookup_pointer_type (TYPE_TARGET_TYPE (VALUE_TYPE (arg1)));
  357.         }
  358.     got_it:
  359.  
  360.       /* Now, say which argument to start evaluating from */
  361.       tem = 2;
  362.     }
  363.       else if (op == STRUCTOP_STRUCT || op == STRUCTOP_PTR)
  364.     {
  365.       /* Hair for method invocations */
  366.       int tem2;
  367.  
  368.       nargs = longest_to_int (exp->elts[pc + 1].longconst) + 1;
  369.       /* First, evaluate the structure into arg2 */
  370.       pc2 = (*pos)++;
  371.       tem2 = longest_to_int (exp->elts[pc2 + 1].longconst);
  372.       *pos += 3 + BYTES_TO_EXP_ELEM (tem2 + 1);
  373.       if (noside == EVAL_SKIP)
  374.         goto nosideret;
  375.  
  376.       if (op == STRUCTOP_STRUCT)
  377.         {
  378.           /* If v is a variable in a register, and the user types
  379.          v.method (), this will produce an error, because v has
  380.          no address.
  381.  
  382.          A possible way around this would be to allocate a
  383.          copy of the variable on the stack, copy in the
  384.          contents, call the function, and copy out the
  385.          contents.  I.e. convert this from call by reference
  386.          to call by copy-return (or whatever it's called).
  387.          However, this does not work because it is not the
  388.          same: the method being called could stash a copy of
  389.          the address, and then future uses through that address
  390.          (after the method returns) would be expected to
  391.          use the variable itself, not some copy of it.  */
  392.           arg2 = evaluate_subexp_for_address (exp, pos, noside);
  393.         }
  394.       else
  395.         {
  396.           arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  397.         }
  398.       /* Now, say which argument to start evaluating from */
  399.       tem = 2;
  400.     }
  401.       else
  402.     {
  403.       nargs = longest_to_int (exp->elts[pc + 1].longconst);
  404.       tem = 0;
  405.     }
  406.       /* Allocate arg vector, including space for the function to be
  407.      called in argvec[0] and a terminating NULL */
  408.       argvec = (value *) alloca (sizeof (value) * (nargs + 2));
  409.       for (; tem <= nargs; tem++)
  410.     /* Ensure that array expressions are coerced into pointer objects. */
  411.     argvec[tem] = evaluate_subexp_with_coercion (exp, pos, noside);
  412.  
  413.       /* signal end of arglist */
  414.       argvec[tem] = 0;
  415.  
  416.       if (op == STRUCTOP_STRUCT || op == STRUCTOP_PTR)
  417.     {
  418.       int static_memfuncp;
  419.       value temp = arg2;
  420.       char tstr[64], mangle_tstr[15], *ptr, *mangle_ptr;
  421.       char *pp;
  422.  
  423.       argvec[1] = arg2;
  424.       argvec[0] = 0;
  425.       strcpy(tstr, &exp->elts[pc2+2].string);
  426.           if (!argvec[0]) 
  427.         {
  428.           temp = arg2;
  429.           argvec[0] =
  430.           value_struct_elt (&temp, argvec+1, tstr,
  431.                   &static_memfuncp,
  432.                   op == STRUCTOP_STRUCT
  433.                   ? "structure" : "structure pointer");
  434.         }
  435.       arg2 = value_from_longest (lookup_pointer_type(VALUE_TYPE (temp)),
  436.              VALUE_ADDRESS (temp)+VALUE_OFFSET (temp));
  437.       argvec[1] = arg2;
  438.  
  439.       if (static_memfuncp)
  440.         {
  441.           argvec[1] = argvec[0];
  442.           nargs--;
  443.           argvec++;
  444.         }
  445.     }
  446.       else if (op == STRUCTOP_MEMBER || op == STRUCTOP_MPTR)
  447.     {
  448.       argvec[1] = arg2;
  449.       argvec[0] = arg1;
  450.     }
  451.  
  452.       if (noside == EVAL_SKIP)
  453.     goto nosideret;
  454.       if (noside == EVAL_AVOID_SIDE_EFFECTS)
  455.     {
  456.       /* If the return type doesn't look like a function type, call an
  457.          error.  This can happen if somebody tries to turn a variable into
  458.          a function call. This is here because people often want to
  459.          call, eg, strcmp, which gdb doesn't know is a function.  If
  460.          gdb isn't asked for it's opinion (ie. through "whatis"),
  461.          it won't offer it. */
  462.  
  463.       struct type *ftype =
  464.         TYPE_TARGET_TYPE (VALUE_TYPE (argvec[0]));
  465.  
  466.       if (ftype)
  467.         return allocate_value (TYPE_TARGET_TYPE (VALUE_TYPE (argvec[0])));
  468.       else
  469.         error ("Expression of type other than \"Function returning ...\" used as function");
  470.     }
  471.       return call_function_by_hand (argvec[0], nargs, argvec + 1);
  472.  
  473.     case STRUCTOP_STRUCT:
  474.       tem = longest_to_int (exp->elts[pc + 1].longconst);
  475.       (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
  476.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  477.       if (noside == EVAL_SKIP)
  478.     goto nosideret;
  479.       if (noside == EVAL_AVOID_SIDE_EFFECTS)
  480.     return value_zero (lookup_struct_elt_type (VALUE_TYPE (arg1),
  481.                            &exp->elts[pc + 2].string,
  482.                            0),
  483.                lval_memory);
  484.       else
  485.     {
  486.       value temp = arg1;
  487.       return value_struct_elt (&temp, (value *)0, &exp->elts[pc + 2].string,
  488.                    (int *) 0, "structure");
  489.     }
  490.  
  491.     case STRUCTOP_PTR:
  492.       tem = longest_to_int (exp->elts[pc + 1].longconst);
  493.       (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
  494.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  495.       if (noside == EVAL_SKIP)
  496.     goto nosideret;
  497.       if (noside == EVAL_AVOID_SIDE_EFFECTS)
  498.     return value_zero (lookup_struct_elt_type (VALUE_TYPE (arg1),
  499.                            &exp->elts[pc + 2].string,
  500.                            0),
  501.                lval_memory);
  502.       else
  503.     {
  504.       value temp = arg1;
  505.       return value_struct_elt (&temp, (value *)0, &exp->elts[pc + 2].string,
  506.                    (int *) 0, "structure pointer");
  507.     }
  508.  
  509.     case STRUCTOP_MEMBER:
  510.       arg1 = evaluate_subexp_for_address (exp, pos, noside);
  511.       goto handle_pointer_to_member;
  512.     case STRUCTOP_MPTR:
  513.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  514.     handle_pointer_to_member:
  515.       arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  516.       if (noside == EVAL_SKIP)
  517.     goto nosideret;
  518.       if (TYPE_CODE (VALUE_TYPE (arg2)) != TYPE_CODE_PTR)
  519.     goto bad_pointer_to_member;
  520.       type = TYPE_TARGET_TYPE (VALUE_TYPE (arg2));
  521.       if (TYPE_CODE (type) == TYPE_CODE_METHOD)
  522.     error ("not implemented: pointer-to-method in pointer-to-member construct");
  523.       if (TYPE_CODE (type) != TYPE_CODE_MEMBER)
  524.     goto bad_pointer_to_member;
  525.       /* Now, convert these values to an address.  */
  526.       arg1 = value_cast (lookup_pointer_type (TYPE_DOMAIN_TYPE (type)),
  527.              arg1);
  528.       arg3 = value_from_longest (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
  529.                  value_as_long (arg1) + value_as_long (arg2));
  530.       return value_ind (arg3);
  531.     bad_pointer_to_member:
  532.       error("non-pointer-to-member value used in pointer-to-member construct");
  533.  
  534.     case BINOP_CONCAT:
  535.       arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
  536.       arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
  537.       if (noside == EVAL_SKIP)
  538.     goto nosideret;
  539.       if (binop_user_defined_p (op, arg1, arg2))
  540.     return value_x_binop (arg1, arg2, op, OP_NULL);
  541.       else
  542.     return value_concat (arg1, arg2);
  543.  
  544.     case BINOP_ASSIGN:
  545.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  546.       arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside);
  547.       if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
  548.     return arg1;
  549.       if (binop_user_defined_p (op, arg1, arg2))
  550.     return value_x_binop (arg1, arg2, op, OP_NULL);
  551.       else
  552.     return value_assign (arg1, arg2);
  553.  
  554.     case BINOP_ASSIGN_MODIFY:
  555.       (*pos) += 2;
  556.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  557.       arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside);
  558.       if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
  559.     return arg1;
  560.       op = exp->elts[pc + 1].opcode;
  561.       if (binop_user_defined_p (op, arg1, arg2))
  562.     return value_x_binop (arg1, arg2, BINOP_ASSIGN_MODIFY, op);
  563.       else if (op == BINOP_ADD)
  564.     arg2 = value_add (arg1, arg2);
  565.       else if (op == BINOP_SUB)
  566.     arg2 = value_sub (arg1, arg2);
  567.       else
  568.     arg2 = value_binop (arg1, arg2, op);
  569.       return value_assign (arg1, arg2);
  570.  
  571.     case BINOP_ADD:
  572.       arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
  573.       arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
  574.       if (noside == EVAL_SKIP)
  575.     goto nosideret;
  576.       if (binop_user_defined_p (op, arg1, arg2))
  577.     return value_x_binop (arg1, arg2, op, OP_NULL);
  578.       else
  579.     return value_add (arg1, arg2);
  580.  
  581.     case BINOP_SUB:
  582.       arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
  583.       arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
  584.       if (noside == EVAL_SKIP)
  585.     goto nosideret;
  586.       if (binop_user_defined_p (op, arg1, arg2))
  587.     return value_x_binop (arg1, arg2, op, OP_NULL);
  588.       else
  589.     return value_sub (arg1, arg2);
  590.  
  591.     case BINOP_MUL:
  592.     case BINOP_DIV:
  593.     case BINOP_REM:
  594.     case BINOP_MOD:
  595.     case BINOP_LSH:
  596.     case BINOP_RSH:
  597.     case BINOP_BITWISE_AND:
  598.     case BINOP_BITWISE_IOR:
  599.     case BINOP_BITWISE_XOR:
  600.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  601.       arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  602.       if (noside == EVAL_SKIP)
  603.     goto nosideret;
  604.       if (binop_user_defined_p (op, arg1, arg2))
  605.     return value_x_binop (arg1, arg2, op, OP_NULL);
  606.       else
  607.     if (noside == EVAL_AVOID_SIDE_EFFECTS
  608.         && (op == BINOP_DIV || op == BINOP_REM || op == BINOP_MOD))
  609.       return value_zero (VALUE_TYPE (arg1), not_lval);
  610.       else
  611.     return value_binop (arg1, arg2, op);
  612.  
  613.     case BINOP_SUBSCRIPT:
  614.       arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
  615.       arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
  616.       if (noside == EVAL_SKIP)
  617.     goto nosideret;
  618.       if (noside == EVAL_AVOID_SIDE_EFFECTS)
  619.     {
  620.       /* If the user attempts to subscript something that has no target
  621.          type (like a plain int variable for example), then report this
  622.          as an error. */
  623.  
  624.       type = TYPE_TARGET_TYPE (VALUE_TYPE (arg1));
  625.       if (type)
  626.         return value_zero (type, VALUE_LVAL (arg1));
  627.       else
  628.         error ("cannot subscript something of type `%s'",
  629.            TYPE_NAME (VALUE_TYPE (arg1)));
  630.     }
  631.                
  632.       if (binop_user_defined_p (op, arg1, arg2))
  633.     return value_x_binop (arg1, arg2, op, OP_NULL);
  634.       else
  635.     return value_subscript (arg1, arg2);
  636.  
  637.     case BINOP_IN:
  638.       arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
  639.       arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
  640.       if (noside == EVAL_SKIP)
  641.     goto nosideret;
  642.       return value_in (arg1, arg2);
  643.       
  644.     case MULTI_SUBSCRIPT:
  645.       (*pos) += 2;
  646.       nargs = longest_to_int (exp->elts[pc + 1].longconst);
  647.       arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
  648.       while (nargs-- > 0)
  649.     {
  650.       arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
  651.       /* FIXME:  EVAL_SKIP handling may not be correct. */
  652.       if (noside == EVAL_SKIP)
  653.         {
  654.           if (nargs > 0)
  655.         {
  656.           continue;
  657.         }
  658.           else
  659.         {
  660.           goto nosideret;
  661.         }
  662.         }
  663.       /* FIXME:  EVAL_AVOID_SIDE_EFFECTS handling may not be correct. */
  664.       if (noside == EVAL_AVOID_SIDE_EFFECTS)
  665.         {
  666.           /* If the user attempts to subscript something that has no target
  667.          type (like a plain int variable for example), then report this
  668.          as an error. */
  669.           
  670.           type = TYPE_TARGET_TYPE (VALUE_TYPE (arg1));
  671.           if (type != NULL)
  672.         {
  673.           arg1 = value_zero (type, VALUE_LVAL (arg1));
  674.           noside = EVAL_SKIP;
  675.           continue;
  676.         }
  677.           else
  678.         {
  679.           error ("cannot subscript something of type `%s'",
  680.              TYPE_NAME (VALUE_TYPE (arg1)));
  681.         }
  682.         }
  683.       
  684.       if (binop_user_defined_p (op, arg1, arg2))
  685.         {
  686.           arg1 = value_x_binop (arg1, arg2, op, OP_NULL);
  687.         }
  688.       else
  689.         {
  690.           arg1 = value_subscript (arg1, arg2);
  691.         }
  692.     }
  693.       return (arg1);
  694.  
  695.     case BINOP_LOGICAL_AND:
  696.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  697.       if (noside == EVAL_SKIP)
  698.     {
  699.       arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  700.       goto nosideret;
  701.     }
  702.       
  703.       oldpos = *pos;
  704.       arg2 = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
  705.       *pos = oldpos;
  706.       
  707.       if (binop_user_defined_p (op, arg1, arg2)) 
  708.     {
  709.       arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  710.       return value_x_binop (arg1, arg2, op, OP_NULL);
  711.     }
  712.       else
  713.     {
  714.       tem = value_logical_not (arg1);
  715.       arg2 = evaluate_subexp (NULL_TYPE, exp, pos,
  716.                   (tem ? EVAL_SKIP : noside));
  717.       return value_from_longest (builtin_type_int,
  718.                   (LONGEST) (!tem && !value_logical_not (arg2)));
  719.     }
  720.  
  721.     case BINOP_LOGICAL_OR:
  722.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  723.       if (noside == EVAL_SKIP)
  724.     {
  725.       arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  726.       goto nosideret;
  727.     }
  728.       
  729.       oldpos = *pos;
  730.       arg2 = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
  731.       *pos = oldpos;
  732.       
  733.       if (binop_user_defined_p (op, arg1, arg2)) 
  734.     {
  735.       arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  736.       return value_x_binop (arg1, arg2, op, OP_NULL);
  737.     }
  738.       else
  739.     {
  740.       tem = value_logical_not (arg1);
  741.       arg2 = evaluate_subexp (NULL_TYPE, exp, pos,
  742.                   (!tem ? EVAL_SKIP : noside));
  743.       return value_from_longest (builtin_type_int,
  744.                   (LONGEST) (!tem || !value_logical_not (arg2)));
  745.     }
  746.  
  747.     case BINOP_EQUAL:
  748.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  749.       arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside);
  750.       if (noside == EVAL_SKIP)
  751.     goto nosideret;
  752.       if (binop_user_defined_p (op, arg1, arg2))
  753.     {
  754.       return value_x_binop (arg1, arg2, op, OP_NULL);
  755.     }
  756.       else
  757.     {
  758.       tem = value_equal (arg1, arg2);
  759.       return value_from_longest (builtin_type_int, (LONGEST) tem);
  760.     }
  761.  
  762.     case BINOP_NOTEQUAL:
  763.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  764.       arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside);
  765.       if (noside == EVAL_SKIP)
  766.     goto nosideret;
  767.       if (binop_user_defined_p (op, arg1, arg2))
  768.     {
  769.       return value_x_binop (arg1, arg2, op, OP_NULL);
  770.     }
  771.       else
  772.     {
  773.       tem = value_equal (arg1, arg2);
  774.       return value_from_longest (builtin_type_int, (LONGEST) ! tem);
  775.     }
  776.  
  777.     case BINOP_LESS:
  778.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  779.       arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside);
  780.       if (noside == EVAL_SKIP)
  781.     goto nosideret;
  782.       if (binop_user_defined_p (op, arg1, arg2))
  783.     {
  784.       return value_x_binop (arg1, arg2, op, OP_NULL);
  785.     }
  786.       else
  787.     {
  788.       tem = value_less (arg1, arg2);
  789.       return value_from_longest (builtin_type_int, (LONGEST) tem);
  790.     }
  791.  
  792.     case BINOP_GTR:
  793.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  794.       arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside);
  795.       if (noside == EVAL_SKIP)
  796.     goto nosideret;
  797.       if (binop_user_defined_p (op, arg1, arg2))
  798.     {
  799.       return value_x_binop (arg1, arg2, op, OP_NULL);
  800.     }
  801.       else
  802.     {
  803.       tem = value_less (arg2, arg1);
  804.       return value_from_longest (builtin_type_int, (LONGEST) tem);
  805.     }
  806.  
  807.     case BINOP_GEQ:
  808.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  809.       arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside);
  810.       if (noside == EVAL_SKIP)
  811.     goto nosideret;
  812.       if (binop_user_defined_p (op, arg1, arg2))
  813.     {
  814.       return value_x_binop (arg1, arg2, op, OP_NULL);
  815.     }
  816.       else
  817.     {
  818.       tem = value_less (arg2, arg1) || value_equal (arg1, arg2);
  819.       return value_from_longest (builtin_type_int, (LONGEST) tem);
  820.     }
  821.  
  822.     case BINOP_LEQ:
  823.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  824.       arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside);
  825.       if (noside == EVAL_SKIP)
  826.     goto nosideret;
  827.       if (binop_user_defined_p (op, arg1, arg2))
  828.     {
  829.       return value_x_binop (arg1, arg2, op, OP_NULL);
  830.     }
  831.       else 
  832.     {
  833.       tem = value_less (arg1, arg2) || value_equal (arg1, arg2);
  834.       return value_from_longest (builtin_type_int, (LONGEST) tem);
  835.     }
  836.  
  837.     case BINOP_REPEAT:
  838.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  839.       arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  840.       if (noside == EVAL_SKIP)
  841.     goto nosideret;
  842.       if (TYPE_CODE (VALUE_TYPE (arg2)) != TYPE_CODE_INT)
  843.     error ("Non-integral right operand for \"@\" operator.");
  844.       if (noside == EVAL_AVOID_SIDE_EFFECTS)
  845.     return allocate_repeat_value (VALUE_TYPE (arg1),
  846.                       longest_to_int (value_as_long (arg2)));
  847.       else
  848.     return value_repeat (arg1, longest_to_int (value_as_long (arg2)));
  849.  
  850.     case BINOP_COMMA:
  851.       evaluate_subexp (NULL_TYPE, exp, pos, noside);
  852.       return evaluate_subexp (NULL_TYPE, exp, pos, noside);
  853.  
  854.     case UNOP_NEG:
  855.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  856.       if (noside == EVAL_SKIP)
  857.     goto nosideret;
  858.       if (unop_user_defined_p (op, arg1))
  859.     return value_x_unop (arg1, op);
  860.       else
  861.     return value_neg (arg1);
  862.  
  863.     case UNOP_COMPLEMENT:
  864.       /* C++: check for and handle destructor names.  */
  865.       op = exp->elts[*pos].opcode;
  866.  
  867.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  868.       if (noside == EVAL_SKIP)
  869.     goto nosideret;
  870.       if (unop_user_defined_p (UNOP_COMPLEMENT, arg1))
  871.     return value_x_unop (arg1, UNOP_COMPLEMENT);
  872.       else
  873.     return value_complement (arg1);
  874.  
  875.     case UNOP_LOGICAL_NOT:
  876.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  877.       if (noside == EVAL_SKIP)
  878.     goto nosideret;
  879.       if (unop_user_defined_p (op, arg1))
  880.     return value_x_unop (arg1, op);
  881.       else
  882.     return value_from_longest (builtin_type_int,
  883.                    (LONGEST) value_logical_not (arg1));
  884.  
  885.     case UNOP_IND:
  886.       if (expect_type && TYPE_CODE (expect_type) == TYPE_CODE_PTR)
  887.         expect_type = TYPE_TARGET_TYPE (expect_type);
  888.       arg1 = evaluate_subexp (expect_type, exp, pos, noside);
  889.       if (noside == EVAL_SKIP)
  890.     goto nosideret;
  891.       if (noside == EVAL_AVOID_SIDE_EFFECTS)
  892.     {
  893.       if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_PTR
  894.           || TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_REF
  895.           /* In C you can dereference an array to get the 1st elt.  */
  896.           || TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_ARRAY
  897.           )
  898.         return value_zero (TYPE_TARGET_TYPE (VALUE_TYPE (arg1)),
  899.                    lval_memory);
  900.       else if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_INT)
  901.         /* GDB allows dereferencing an int.  */
  902.         return value_zero (builtin_type_int, lval_memory);
  903.       else
  904.         error ("Attempt to take contents of a non-pointer value.");
  905.     }
  906.       return value_ind (arg1);
  907.  
  908.     case UNOP_ADDR:
  909.       /* C++: check for and handle pointer to members.  */
  910.       
  911.       op = exp->elts[*pos].opcode;
  912.  
  913.       if (noside == EVAL_SKIP)
  914.     {
  915.       if (op == OP_SCOPE)
  916.         {
  917.           int temm = longest_to_int (exp->elts[pc+3].longconst);
  918.           (*pos) += 3 + BYTES_TO_EXP_ELEM (temm + 1);
  919.         }
  920.       else
  921.         evaluate_subexp (expect_type, exp, pos, EVAL_SKIP);
  922.       goto nosideret;
  923.     }
  924.  
  925.       return evaluate_subexp_for_address (exp, pos, noside);
  926.  
  927.     case UNOP_SIZEOF:
  928.       if (noside == EVAL_SKIP)
  929.     {
  930.       evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
  931.       goto nosideret;
  932.     }
  933.       return evaluate_subexp_for_sizeof (exp, pos);
  934.  
  935.     case UNOP_CAST:
  936.       (*pos) += 2;
  937.       arg1 = evaluate_subexp (expect_type, exp, pos, noside);
  938.       if (noside == EVAL_SKIP)
  939.     goto nosideret;
  940.       return value_cast (exp->elts[pc + 1].type, arg1);
  941.  
  942.     case UNOP_MEMVAL:
  943.       (*pos) += 2;
  944.       arg1 = evaluate_subexp (expect_type, exp, pos, noside);
  945.       if (noside == EVAL_SKIP)
  946.     goto nosideret;
  947.       if (noside == EVAL_AVOID_SIDE_EFFECTS)
  948.     return value_zero (exp->elts[pc + 1].type, lval_memory);
  949.       else
  950.     return value_at_lazy (exp->elts[pc + 1].type,
  951.                   value_as_pointer (arg1));
  952.  
  953.     case UNOP_PREINCREMENT:
  954.       arg1 = evaluate_subexp (expect_type, exp, pos, noside);
  955.       if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
  956.     return arg1;
  957.       else if (unop_user_defined_p (op, arg1))
  958.     {
  959.       return value_x_unop (arg1, op);
  960.     }
  961.       else
  962.     {
  963.       arg2 = value_add (arg1, value_from_longest (builtin_type_char, 
  964.                            (LONGEST) 1));
  965.       return value_assign (arg1, arg2);
  966.     }
  967.  
  968.     case UNOP_PREDECREMENT:
  969.       arg1 = evaluate_subexp (expect_type, exp, pos, noside);
  970.       if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
  971.     return arg1;
  972.       else if (unop_user_defined_p (op, arg1))
  973.     {
  974.       return value_x_unop (arg1, op);
  975.     }
  976.       else
  977.     {
  978.       arg2 = value_sub (arg1, value_from_longest (builtin_type_char, 
  979.                            (LONGEST) 1));
  980.       return value_assign (arg1, arg2);
  981.     }
  982.  
  983.     case UNOP_POSTINCREMENT:
  984.       arg1 = evaluate_subexp (expect_type, exp, pos, noside);
  985.       if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
  986.     return arg1;
  987.       else if (unop_user_defined_p (op, arg1))
  988.     {
  989.       return value_x_unop (arg1, op);
  990.     }
  991.       else
  992.     {
  993.       arg2 = value_add (arg1, value_from_longest (builtin_type_char, 
  994.                            (LONGEST) 1));
  995.       value_assign (arg1, arg2);
  996.       return arg1;
  997.     }
  998.  
  999.     case UNOP_POSTDECREMENT:
  1000.       arg1 = evaluate_subexp (expect_type, exp, pos, noside);
  1001.       if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
  1002.     return arg1;
  1003.       else if (unop_user_defined_p (op, arg1))
  1004.     {
  1005.       return value_x_unop (arg1, op);
  1006.     }
  1007.       else
  1008.     {
  1009.       arg2 = value_sub (arg1, value_from_longest (builtin_type_char, 
  1010.                            (LONGEST) 1));
  1011.       value_assign (arg1, arg2);
  1012.       return arg1;
  1013.     }
  1014.     
  1015.     case OP_THIS:
  1016.       (*pos) += 1;
  1017.       return value_of_this (1);
  1018.  
  1019.     case OP_TYPE:
  1020.       error ("Attempt to use a type name as an expression");
  1021.  
  1022.     default:
  1023.       /* Removing this case and compiling with gcc -Wall reveals that
  1024.      a lot of cases are hitting this case.  Some of these should
  1025.      probably be removed from expression.h (e.g. do we need a BINOP_SCOPE
  1026.      and an OP_SCOPE?); others are legitimate expressions which are
  1027.      (apparently) not fully implemented.
  1028.  
  1029.      If there are any cases landing here which mean a user error,
  1030.      then they should be separate cases, with more descriptive
  1031.      error messages.  */
  1032.  
  1033.       error ("\
  1034. GDB does not (yet) know how to evaluated that kind of expression");
  1035.     }
  1036.  
  1037.  nosideret:
  1038.   return value_from_longest (builtin_type_long, (LONGEST) 1);
  1039. }
  1040.  
  1041. /* Evaluate a subexpression of EXP, at index *POS,
  1042.    and return the address of that subexpression.
  1043.    Advance *POS over the subexpression.
  1044.    If the subexpression isn't an lvalue, get an error.
  1045.    NOSIDE may be EVAL_AVOID_SIDE_EFFECTS;
  1046.    then only the type of the result need be correct.  */
  1047.  
  1048. static value
  1049. evaluate_subexp_for_address (exp, pos, noside)
  1050.      register struct expression *exp;
  1051.      register int *pos;
  1052.      enum noside noside;
  1053. {
  1054.   enum exp_opcode op;
  1055.   register int pc;
  1056.   struct symbol *var;
  1057.  
  1058.   pc = (*pos);
  1059.   op = exp->elts[pc].opcode;
  1060.  
  1061.   switch (op)
  1062.     {
  1063.     case UNOP_IND:
  1064.       (*pos)++;
  1065.       return evaluate_subexp (NULL_TYPE, exp, pos, noside);
  1066.  
  1067.     case UNOP_MEMVAL:
  1068.       (*pos) += 3;
  1069.       return value_cast (lookup_pointer_type (exp->elts[pc + 1].type),
  1070.              evaluate_subexp (NULL_TYPE, exp, pos, noside));
  1071.  
  1072.     case OP_VAR_VALUE:
  1073.       var = exp->elts[pc + 2].symbol;
  1074.  
  1075.       /* C++: The "address" of a reference should yield the address
  1076.        * of the object pointed to. Let value_addr() deal with it. */
  1077.       if (TYPE_CODE (SYMBOL_TYPE (var)) == TYPE_CODE_REF)
  1078.         goto default_case;
  1079.  
  1080.       (*pos) += 4;
  1081.       if (noside == EVAL_AVOID_SIDE_EFFECTS)
  1082.     {
  1083.       struct type *type =
  1084.         lookup_pointer_type (SYMBOL_TYPE (var));
  1085.       enum address_class sym_class = SYMBOL_CLASS (var);
  1086.  
  1087.       if (sym_class == LOC_CONST
  1088.           || sym_class == LOC_CONST_BYTES
  1089.           || sym_class == LOC_REGISTER
  1090.           || sym_class == LOC_REGPARM)
  1091.         error ("Attempt to take address of register or constant.");
  1092.  
  1093.     return
  1094.       value_zero (type, not_lval);
  1095.     }
  1096.       else
  1097.     return
  1098.       locate_var_value
  1099.         (var,
  1100.          block_innermost_frame (exp->elts[pc + 1].block));
  1101.  
  1102.     default:
  1103.     default_case:
  1104.       if (noside == EVAL_AVOID_SIDE_EFFECTS)
  1105.     {
  1106.       value x = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  1107.       if (VALUE_LVAL (x) == lval_memory)
  1108.         return value_zero (lookup_pointer_type (VALUE_TYPE (x)),
  1109.                    not_lval);
  1110.       else
  1111.         error ("Attempt to take address of non-lval");
  1112.     }
  1113.       return value_addr (evaluate_subexp (NULL_TYPE, exp, pos, noside));
  1114.     }
  1115. }
  1116.  
  1117. /* Evaluate like `evaluate_subexp' except coercing arrays to pointers.
  1118.    When used in contexts where arrays will be coerced anyway, this is
  1119.    equivalent to `evaluate_subexp' but much faster because it avoids
  1120.    actually fetching array contents (perhaps obsolete now that we have
  1121.    VALUE_LAZY).
  1122.  
  1123.    Note that we currently only do the coercion for C expressions, where
  1124.    arrays are zero based and the coercion is correct.  For other languages,
  1125.    with nonzero based arrays, coercion loses.  Use CAST_IS_CONVERSION
  1126.    to decide if coercion is appropriate.
  1127.  
  1128.    */
  1129.  
  1130. static value
  1131. evaluate_subexp_with_coercion (exp, pos, noside)
  1132.      register struct expression *exp;
  1133.      register int *pos;
  1134.      enum noside noside;
  1135. {
  1136.   register enum exp_opcode op;
  1137.   register int pc;
  1138.   register value val;
  1139.   struct symbol *var;
  1140.  
  1141.   pc = (*pos);
  1142.   op = exp->elts[pc].opcode;
  1143.  
  1144.   switch (op)
  1145.     {
  1146.     case OP_VAR_VALUE:
  1147.       var = exp->elts[pc + 2].symbol;
  1148.       if (TYPE_CODE (SYMBOL_TYPE (var)) == TYPE_CODE_ARRAY
  1149.       && CAST_IS_CONVERSION)
  1150.     {
  1151.       (*pos) += 4;
  1152.       val =
  1153.         locate_var_value
  1154.           (var, block_innermost_frame (exp->elts[pc + 1].block));
  1155.       return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (SYMBOL_TYPE (var))),
  1156.                  val);
  1157.     }
  1158.       /* FALLTHROUGH */
  1159.  
  1160.     default:
  1161.       return evaluate_subexp (NULL_TYPE, exp, pos, noside);
  1162.     }
  1163. }
  1164.  
  1165. /* Evaluate a subexpression of EXP, at index *POS,
  1166.    and return a value for the size of that subexpression.
  1167.    Advance *POS over the subexpression.  */
  1168.  
  1169. static value
  1170. evaluate_subexp_for_sizeof (exp, pos)
  1171.      register struct expression *exp;
  1172.      register int *pos;
  1173. {
  1174.   enum exp_opcode op;
  1175.   register int pc;
  1176.   value val;
  1177.  
  1178.   pc = (*pos);
  1179.   op = exp->elts[pc].opcode;
  1180.  
  1181.   switch (op)
  1182.     {
  1183.       /* This case is handled specially
  1184.      so that we avoid creating a value for the result type.
  1185.      If the result type is very big, it's desirable not to
  1186.      create a value unnecessarily.  */
  1187.     case UNOP_IND:
  1188.       (*pos)++;
  1189.       val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
  1190.       return value_from_longest (builtin_type_int, (LONGEST)
  1191.               TYPE_LENGTH (TYPE_TARGET_TYPE (VALUE_TYPE (val))));
  1192.  
  1193.     case UNOP_MEMVAL:
  1194.       (*pos) += 3;
  1195.       return value_from_longest (builtin_type_int, 
  1196.                   (LONGEST) TYPE_LENGTH (exp->elts[pc + 1].type));
  1197.  
  1198.     case OP_VAR_VALUE:
  1199.       (*pos) += 4;
  1200.       return
  1201.     value_from_longest
  1202.       (builtin_type_int,
  1203.        (LONGEST) TYPE_LENGTH (SYMBOL_TYPE (exp->elts[pc + 2].symbol)));
  1204.  
  1205.     default:
  1206.       val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
  1207.       return value_from_longest (builtin_type_int,
  1208.                   (LONGEST) TYPE_LENGTH (VALUE_TYPE (val)));
  1209.     }
  1210. }
  1211.  
  1212. /* Parse a type expression in the string [P..P+LENGTH). */
  1213.  
  1214. struct type *
  1215. parse_and_eval_type (p, length)
  1216.      char *p;
  1217.      int length;
  1218. {
  1219.     char *tmp = (char *)alloca (length + 4);
  1220.     struct expression *expr;
  1221.     tmp[0] = '(';
  1222.     memcpy (tmp+1, p, length);
  1223.     tmp[length+1] = ')';
  1224.     tmp[length+2] = '0';
  1225.     tmp[length+3] = '\0';
  1226.     expr = parse_expression (tmp);
  1227.     if (expr->elts[0].opcode != UNOP_CAST)
  1228.     error ("Internal error in eval_type.");
  1229.     return expr->elts[1].type;
  1230. }
  1231.